/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* includes (local) ----------------------------------------------------------*/
#include "x_bug.h"
/* includes (standard library, system) ---------------------------------------*/
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
#include <x_it.h>
#include <a_trace.h>

/* defines -------------------------------------------------------------------*/
/* typedefs ------------------------------------------------------------------*/
/* macro ---------------------------------------------------------------------*/
/* variables (global) --------------------------------------------------------*/

volatile int __bug_dummy_check = 0;

/* variables (extern) --------------------------------------------------------*/
/* variables (local) ---------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/
/* functions -----------------------------------------------------------------*/

void __bug(const char *info)
{
    (void)it_lock();

#ifdef CONFIG_KPRINTF
    /* if __bug beening invoked directly */

    if (info[0] != '\0') {
        kprintf("BUG, \"%s\"\n", info);
    }
#endif

    call_trace();

    while (__bug_dummy_check == 0) {
    }
}
